﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using WS.EKA.FJYCM.Business.DAL;

namespace WS.EKA.FJYCM.Business
{
    public class AssetAccess
    {
        static IDB db = DBFactory.CreateARDB();
        public static string GetProvincialAccessJson()
        {
            var rdb = DBFactory.CreateARDB();
            string sql = @"select a.* from ((select type,count(type) total from AST_BMC_Hardware where type in('服务器','网络设备','安全设备','存储设备') and datasetid='BMC.ASSET' and (markasdeleted=0 or markasdeleted is null) and company='福建省烟草专卖局' group by type ) 
                           union all (select '应用系统' as type,count(*) total from AST_BMC_AppSystem  where category='应用系统' and datasetid='BMC.ASSET' and (markasdeleted=0 or markasdeleted is null) and company='福建省烟草专卖局') )a order by a.total desc ";
            var table = rdb.ExecuteDataTable(sql);
            List<string> list = new List<string>();
            foreach (DataRow row in table.Rows)
            {
                list.Add(string.Format("['{0}',{1}]", row["type"], row["total"]));
            }
            StringBuilder json = new StringBuilder();
            json.Append("[");
            json.Append(string.Join(",", list));
            json.Append("]");
            return json.ToString();
        }


    }
}
